<template>
  <div>
    <PlusPage :columns="tableConfig" :table="{ adaptive: true }" :request="getList" />
  </div>
</template>

<script lang="ts" setup>
import type { PlusColumn, PageInfo } from '@wlydfe/pro-ui'

const getList = async (
  query: PageInfo & {
    status?: string
    name?: string
  },
) => {
  const { page = 1, pageSize = 10, status, name } = query || {}
  const total = 1000
  const List = Array.from({ length: total }).map((_, index) => {
    return {
      id: index,
      name: `${index}name`,
      status: String(index % 3),
      tag: index === 1 ? 'success' : index === 2 ? 'warning' : index === 3 ? 'info' : 'danger',
      progress: index * 10,
      rate: index > 3 ? 2 : 3.5,
      switch: index % 2 === 0 ? true : false,
      img: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
      time: new Date(),
      custom: `custom${index}`,
    }
  })

  const mockList = List.filter(item => {
    if (status && status !== item.status) {
      return false
    }

    if (name && name !== item.name) {
      return false
    }

    return true
  })

  const pageList = mockList.filter(
    (_, index) => index < pageSize * page && index >= pageSize * (page - 1),
  )

  // 等待2s
  await new Promise(resolve => {
    setTimeout(() => {
      resolve('')
    }, 2000)
  })

  return { data: pageList, success: true, total: mockList.length }
}

const tableConfig: PlusColumn[] = {{TABLE_CONFIG}}
</script>
